package com.baizhi.service.impl;

import com.baizhi.dao.CmfzBannerDao;
import com.baizhi.entity.CmfzBanner;
import com.baizhi.service.CmfzBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CmfzBannerServiceImpl implements CmfzBannerService {
    @Autowired
    private CmfzBannerDao cbd;
    @Override
    @Transactional(readOnly = true)
    public Map<String,Object> bannerListByPage(int pageNo, int pageSize) {
        Page<CmfzBanner> cmfzBanners = new Page<>(pageNo, pageSize);
        Page<CmfzBanner> page = cbd.selectPage(cmfzBanners, null);
        Map<String, Object> map = new HashMap<>();

        map.put("code",0);
        map.put("msg","");
        map.put("data",page.getRecords());
        map.put("count",page.getTotal());
        return map;
    }

    @Override
    public void insert(CmfzBanner banner) {
        cbd.insert(banner);
    }

    @Override
    public void delete(int id) {
        cbd.deleteById(id);
    }
}
